<?php


class Model_Ps_Onlineorders extends Zend_Db_Table_Abstract {

	protected $_name = 'ps_orders';
	protected $_adaptor = 'db_remote';
	protected $_primary = 'id_order';
	
	public function getOnlineorders( $idOrder){
		
		$row = $this->fetchRow("`id_order` = ". $idOrder);
		if(!$row) return false;
		return $row->toArray();		
		
		}
		
	public function addOnlineorders( $reference , $idShopGroup , $idShop , $idCarrier , $idLang , $idCustomer , $idCart , $idCurrency , $idAddressDelivery , $idAddressInvoice , $currentState , $secureKey , $payment , $conversionRate , $module , $recyclable , $gift , $giftMessage , $mobileTheme , $shippingNumber , $totalDiscounts , $totalDiscountsTaxExcl , $totalDiscountsTaxIncl , $totalPaid , $totalPaidTaxExcl , $totalPaidTaxIncl , $totalPaidReal , $totalProducts , $totalProductsWt , $totalShipping , $totalShippingTaxExcl , $totalShippingTaxIncl , $carrierTaxRate , $totalWrapping , $totalWrappingTaxExcl , $totalWrappingTaxIncl , $invoiceNumber , $deliveryNumber , $invoiceDate , $deliveryDate , $valid , $dateAdd , $dateUpd){
		
		$data = array(
			
         "reference" =>  $reference ,
         "id_shop_group" =>  $idShopGroup ,
         "id_shop" =>  $idShop ,
         "id_carrier" =>  $idCarrier ,
         "id_lang" =>  $idLang ,
         "id_customer" =>  $idCustomer ,
         "id_cart" =>  $idCart ,
         "id_currency" =>  $idCurrency ,
         "id_address_delivery" =>  $idAddressDelivery ,
         "id_address_invoice" =>  $idAddressInvoice ,
         "current_state" =>  $currentState ,
         "secure_key" =>  $secureKey ,
         "payment" =>  $payment ,
         "conversion_rate" =>  $conversionRate ,
         "module" =>  $module ,
         "recyclable" =>  $recyclable ,
         "gift" =>  $gift ,
         "gift_message" =>  $giftMessage ,
         "mobile_theme" =>  $mobileTheme ,
         "shipping_number" =>  $shippingNumber ,
         "total_discounts" =>  $totalDiscounts ,
         "total_discounts_tax_excl" =>  $totalDiscountsTaxExcl ,
         "total_discounts_tax_incl" =>  $totalDiscountsTaxIncl ,
         "total_paid" =>  $totalPaid ,
         "total_paid_tax_excl" =>  $totalPaidTaxExcl ,
         "total_paid_tax_incl" =>  $totalPaidTaxIncl ,
         "total_paid_real" =>  $totalPaidReal ,
         "total_products" =>  $totalProducts ,
         "total_products_wt" =>  $totalProductsWt ,
         "total_shipping" =>  $totalShipping ,
         "total_shipping_tax_excl" =>  $totalShippingTaxExcl ,
         "total_shipping_tax_incl" =>  $totalShippingTaxIncl ,
         "carrier_tax_rate" =>  $carrierTaxRate ,
         "total_wrapping" =>  $totalWrapping ,
         "total_wrapping_tax_excl" =>  $totalWrappingTaxExcl ,
         "total_wrapping_tax_incl" =>  $totalWrappingTaxIncl ,
         "invoice_number" =>  $invoiceNumber ,
         "delivery_number" =>  $deliveryNumber ,
         "invoice_date" =>  $invoiceDate ,
         "delivery_date" =>  $deliveryDate ,
         "valid" =>  $valid ,
         "date_add" =>  $dateAdd ,
         "date_upd" =>  $dateUpd 
	
			);
		$this->insert($data);
		
		}
		
	public function updateOnlineorders(  $idOrder ,  $reference , $idShopGroup , $idShop , $idCarrier , $idLang , $idCustomer , $idCart , $idCurrency , $idAddressDelivery , $idAddressInvoice , $currentState , $secureKey , $payment , $conversionRate , $module , $recyclable , $gift , $giftMessage , $mobileTheme , $shippingNumber , $totalDiscounts , $totalDiscountsTaxExcl , $totalDiscountsTaxIncl , $totalPaid , $totalPaidTaxExcl , $totalPaidTaxIncl , $totalPaidReal , $totalProducts , $totalProductsWt , $totalShipping , $totalShippingTaxExcl , $totalShippingTaxIncl , $carrierTaxRate , $totalWrapping , $totalWrappingTaxExcl , $totalWrappingTaxIncl , $invoiceNumber , $deliveryNumber , $invoiceDate , $deliveryDate , $valid , $dateAdd , $dateUpd){
		$data = array(
			
         "reference" =>  $reference ,
         "id_shop_group" =>  $idShopGroup ,
         "id_shop" =>  $idShop ,
         "id_carrier" =>  $idCarrier ,
         "id_lang" =>  $idLang ,
         "id_customer" =>  $idCustomer ,
         "id_cart" =>  $idCart ,
         "id_currency" =>  $idCurrency ,
         "id_address_delivery" =>  $idAddressDelivery ,
         "id_address_invoice" =>  $idAddressInvoice ,
         "current_state" =>  $currentState ,
         "secure_key" =>  $secureKey ,
         "payment" =>  $payment ,
         "conversion_rate" =>  $conversionRate ,
         "module" =>  $module ,
         "recyclable" =>  $recyclable ,
         "gift" =>  $gift ,
         "gift_message" =>  $giftMessage ,
         "mobile_theme" =>  $mobileTheme ,
         "shipping_number" =>  $shippingNumber ,
         "total_discounts" =>  $totalDiscounts ,
         "total_discounts_tax_excl" =>  $totalDiscountsTaxExcl ,
         "total_discounts_tax_incl" =>  $totalDiscountsTaxIncl ,
         "total_paid" =>  $totalPaid ,
         "total_paid_tax_excl" =>  $totalPaidTaxExcl ,
         "total_paid_tax_incl" =>  $totalPaidTaxIncl ,
         "total_paid_real" =>  $totalPaidReal ,
         "total_products" =>  $totalProducts ,
         "total_products_wt" =>  $totalProductsWt ,
         "total_shipping" =>  $totalShipping ,
         "total_shipping_tax_excl" =>  $totalShippingTaxExcl ,
         "total_shipping_tax_incl" =>  $totalShippingTaxIncl ,
         "carrier_tax_rate" =>  $carrierTaxRate ,
         "total_wrapping" =>  $totalWrapping ,
         "total_wrapping_tax_excl" =>  $totalWrappingTaxExcl ,
         "total_wrapping_tax_incl" =>  $totalWrappingTaxIncl ,
         "invoice_number" =>  $invoiceNumber ,
         "delivery_number" =>  $deliveryNumber ,
         "invoice_date" =>  $invoiceDate ,
         "delivery_date" =>  $deliveryDate ,
         "valid" =>  $valid ,
         "date_add" =>  $dateAdd ,
         "date_upd" =>  $dateUpd 
	
			);
			
		$this->update($data,"`id_order` = ". $idOrder);
		}
		
	public function deleteOnlineorders( $idOrder){
		
		$this->delete("`id_order` = ". $idOrder);
		
		}	
	
	public function listAll(){
		
		$rows =$this->fetchAll("1","id_order DESC ");
		if(!$rows) return false;
		return $rows->toArray();			
		
		}	
		
	public function getLatestOrder(){
		
		$rows = $this->fetchRow("1","id_order DESC");
		return $rows['id_order'];
	}	
}



?>